package com.pet.controller;

import com.pet.pojo.Item;
import com.pet.service.ItemService;
import com.pet.vo.PageResult;
import com.pet.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.sound.midi.Soundbank;
import java.util.List;

/*  何剑  */
@RestController
@CrossOrigin
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private ItemService itemService;
    private  Integer id = 4;
    private String keyword;

    @GetMapping("/getData/{id}")
    public SysResult getById(@PathVariable Integer id){
        this.id = id;
        this.keyword = null;
        if (id == null){
            return SysResult.fail();
        }
        return SysResult.success();
    }

    @RequestMapping("/getPage/{pageNum}/{pageSize}")
    public SysResult getByPage(PageResult result){
        if(id != null){
            PageResult data = itemService.getData(id,result);
            return  SysResult.success(data);
        }else{
            PageResult data = itemService.getDataByKeyword(keyword,result);
            return  SysResult.success(data);
        }
    }

    @GetMapping("/search")
    public SysResult search(String keyword){
        this.keyword = keyword;
        this.id = null;
        return SysResult.success();
    }

}
